
package com.zj.system.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

public class AliyunSmsUtil {
    public static String sendSms(String phone) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI78XQAZq2s5Rv", "qdyZxR0x4LoUpTVbuyvCGdcrhEyw7H");
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("sendSms");
        request.putQueryParameter("PhoneNumbers", phone);
        request.putQueryParameter("SignName", "智友");
        request.putQueryParameter("TemplateCode", "SMS_173342144");
        String code = (Math.random() + "").substring(2, 8);
        request.putQueryParameter("TemplateParam", "{\"code\":" + code + "}");

        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException var6) {
            var6.printStackTrace();
        } catch (ClientException var7) {
            var7.printStackTrace();
        }

        return code;
    }
}
